<template>
    <a-spin :spinning="confirmLoading">
        <j-form-container :disabled="formDisabled">
            <a-form-model ref="form" :model="model"  :rules="validatorRules" slot="detail">
                <!-- useful_auto_generate_section_start -->

                <a-row>
                    <a-col :span="12">
                        <a-form-model-item label="链接信息"  :labelCol="labelCol_3" :wrapperCol="wrapperCol_3" required >
                            <a-textarea v-model="model.url" placeholder="请输入链接信息" />
<!--                            <a-input v-model="model.url" placeholder="请输入链接" />-->
                        </a-form-model-item>
                    </a-col>
                  <a-col :span="4">
                    <a-form-model-item label="评论区"  :labelCol="labelCol_3" :wrapperCol="wrapperCol_3" required >
                      <a-switch v-model="model.commentStatus" checked-children="开" un-checked-children="关" default-checked />
                    </a-form-model-item>
                  </a-col>

                  <a-col :span="4">
                    <a-form-model-item   :labelCol="labelCol_3" :wrapperCol="wrapperCol_3" >
                      <a-button @click="loginHandle" type="primary" :loading="confirmLoading"> 网站导出</a-button>
                    </a-form-model-item>
                  </a-col>
                    <a-col :span="4">
                        <a-form-model-item   :labelCol="labelCol_3" :wrapperCol="wrapperCol_3" >
                            <a-button @click="loginWxHandle" type="primary" :loading="confirmLoading"> 微信导出</a-button>
                        </a-form-model-item>
                    </a-col>
                </a-row>

<!--              <a-row>-->
<!--                <a-col :span="20">-->
<!--                  <a-form-model-item label="维信排名请求信息"  :labelCol="labelCol_1" :wrapperCol="wrapperCol_1" >-->
<!--                    <a-textarea v-model="model.ck" placeholder="请输入Cookie" />-->
<!--                  </a-form-model-item>-->
<!--                </a-col>-->
<!--                <a-col :span="4">-->
<!--                  <a-form-model-item   :labelCol="labelCol_2" :wrapperCol="wrapperCol_2" >-->
<!--                    <a-button @click="loginWxHandle" type="primary" :loading="confirmLoading"> 微信导出</a-button>-->
<!--                  </a-form-model-item>-->
<!--                </a-col>-->
<!--              </a-row>-->



<!--                <a-row>-->
<!--                    <a-col :span="24">-->
<!--                        <a-form-model-item label="Cookie"  :labelCol="labelCol_1" :wrapperCol="wrapperCol_1" >-->
<!--                            <a-textarea v-model="model.cookie" placeholder="请输入Cookie" />-->
<!--                        </a-form-model-item>-->
<!--                    </a-col>-->
<!--                </a-row>-->
                <!-- useful_auto_generate_section_end -->

            </a-form-model>
          <div style="text-align: left">
            <h3 style="text-align: left">使用说明：</h3>
            <ul>
              <li>
                ”链接信息“支持网站链接地址，比如：直播间地址，排行榜地址，必须支持网站打开，导出时必须选择”网站导出“
              </li>
              <li>
                ”链接信息“支持仅微信打开链接地址，比如：直播间地址，排行榜地址，仅支持微信打开，导出时必须选择”微信导出“
              </li>
              <li>
                如果直播间有评论区，则导出出必须勾上评论区，不然导不出数据，否则必须不用勾上
              </li>
              <li>
                针对微信导出的链接信息，通过黄色代理工具获取，点击搜索>选择URL>输入搜索关键字>右击copy curl，然后复制到链接信息文本框中
              </li>
              <strong>直播间搜索关键字:</strong>
              <li>
                /_alive/bff_h5/msg/list
              </li>
              <strong>排行榜搜索关键字:</strong>
              <li>
                /xe.data.learn_center.get_user_rank_list/1.0.0
              </li>

            </ul>
          </div>



        </j-form-container>
    </a-spin>
</template>


<script>

    import { httpAction, getAction,addYearsToDateString,setToken } from '@/api/manage'
    import { getDataOptionList,requestSetData, requestSetOption } from '@/utils/util'
    import { FormMixin } from '@/mixins/FormMixin'
    import moment from 'moment'

    export default {
        name: 'UserForm',
        mixins: [ FormMixin],
        components: {
        },
        props: {
            //表单禁用
            disabled: {
                type: Boolean,
                default: false,
                required: false
            }
        },
        data () {
            return {
                model:{
                },
                confirmLoading: false,
                validatorRules: {
                },
                //useful_auto_generate_section_start
                statusOptions:getDataOptionList('userStatusList'),
                activeOptions:getDataOptionList('userActiveList'),
                auditUserIdOptions:[],
                //useful_auto_generate_section_end
                positionOptions:[],
                url: {
                    login: "/user/login",
                    exportWin: "/system/openWin",
                    exportWinWx: "/system/openWx",
                    loginSuccess: "http://127.0.0.1:28081/user/loginSuccess",
                    queryById: "/user/detail"
                },
                filter:(inputValue, path) => {
                    return path.some(option => option.title.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
                },
            }
        },
        computed: {
            formDisabled(){
                return this.disabled
            },
        },
        created () {
            let $this = this;
            //useful_auto_generate_section_start
            // requestSetOptions("/user/anonymous/user/listAll",{},function(options){$this.auditUserIdOptions=options;},{label:'userName',value:'id'});
            //useful_auto_generate_section_end
            // requestSetData("/system/anonymous/dataDict/listTree",{value:'userPosition',idToValue:true},function(options){$this.positionOptions=options[0].children;},{});

            //备份model原始值
            this.modelDefault = JSON.parse(JSON.stringify(this.model));

        },
        methods: {
            add () {
                this.edit(this.modelDefault);
            },
            edit (record) {
                this.model = Object.assign({}, record);
                this.visible = true;
            },
            handleChange(value) {
                // console.log(`selected `);
            },
            onChange(e) {
                console.log('radio1 checked', e.target.value);
            },
            handleDateChange(value,options) {
                console.log("timeValue="+value);
                // let dateArray = value.toString().split(",")
                let format = options['format'] || 'YYYY-MM-DD';
                let frmtValue = value.format(format);
                let gmtExpire = addYearsToDateString(frmtValue,5);
                this.model.gmtExpire = gmtExpire;
            },
            loginHandle () {
                const $this= this;
                if(!$this.model.url){
                    $this.$message.warning("请输入链接信息再操作");
                    return;
                }else if(!$this.model.url.startsWith('https://')){
                    $this.$message.warning("请按说明输入正确的链接信息");
                    return;
                }
                // 触发表单验证
                this.$refs.form.validate(valid=>{
                    if (valid) {
                        $this.confirmLoading = true;
                        httpAction(this.url.exportWin,$this.model,"POST").then((res)=>{
                            if(res.success){
                                $this.$message.success('数据导出中..');
                            }else{
                                $this.$message.warning(res.message);
                            }
                        }).finally(() => {
                            $this.confirmLoading = false;
                        })
                    }

                })
            },
          loginWxHandle () {
            const $this= this;
            if(!$this.model.url){
              $this.$message.warning("请输入微信直播排名请求信息");
              return;
            }
            // 触发表单验证
            this.$refs.form.validate(valid=>{
              if (valid) {
                $this.confirmLoading = true;
                httpAction(this.url.exportWinWx,$this.model,"POST").then((res)=>{
                  if(res.success){
                    $this.$message.success('数据导出中..');
                  }else{
                    $this.$message.warning(res.message);
                  }
                }).finally(() => {
                  $this.confirmLoading = false;
                })
              }

            })
          },
        }
    }
</script>
